package com.swn.cm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swn.common.util.DbHelper;
import com.swn.common.util.PageListData;

@Service
public class StudentPracticeService {

	@Autowired
	private DbHelper dbHelper;
	
	public List<Map<String, Object>> stulist(PageListData page,Map<String, Object> paramMap) {
		StringBuffer sql = new StringBuffer();
		sql.append(" select s.id, s.name, s.age, s.sex, s.class_name, s.class_code, s.create_time, s.head_img from student_myw s ");
		String name = (String) paramMap.get("name");
		if (StringUtils.isNotBlank(name)) {
			sql.append("where s.name like :name");
			paramMap.put("name", "%"+name+"%");
		}
		sql.append(" ORDER BY s.create_time DESC");
		
		List<Map<String,Object>> pageMapList = null;
		try {
			pageMapList  = dbHelper.queryPageMapList(page, sql.toString(), paramMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageMapList;
	}

	public Map<String, Object> queryClassList() {
		HashMap<String, Object> resultMapList = new HashMap<String, Object>();
		
		//查询sql
		String sql = "select c.id, c.code, c.`name` from shop_cm_class c";
		
		//连接查询数据
		List<Map<String, Object>> classMapList = dbHelper.queryForList(sql, null);
		resultMapList.put("data", classMapList);
		return resultMapList;
	}

	public Map<String, Object> queryStuById(String id) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("id", id);
		return dbHelper.queryMapById(paramMap, "student_myw");
	}

	public int saveStu(Map<String, Object> jsonMap) {
		return dbHelper.saveMap(jsonMap, "student_myw");
	}

}
